package com.ruoyi.system.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.system.domain.TourismPersonnel;
import com.ruoyi.system.mapper.TourismPersonnelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.TourismRecordMapper;
import com.ruoyi.system.domain.TourismRecord;
import com.ruoyi.system.service.ITourismRecordService;

import javax.annotation.Resource;

/**
 * 预约人Service业务层处理
 *
 * @author gqd
 * @date 2021-02-04
 */
@Service
public class TourismRecordServiceImpl implements ITourismRecordService
{
    @Autowired
    private TourismRecordMapper tourismRecordMapper;
    @Resource
    private TourismPersonnelMapper tourismPersonnelMapper;

    /**
     * 查询预约人
     *
     * @param id 预约人ID
     * @return 预约人
     */
    @Override
    public TourismRecord selectTourismRecordById(Long id)
    {
        return tourismRecordMapper.selectTourismRecordById(id);
    }

    /**
     * 查询预约人列表
     *
     * @param tourismRecord 预约人
     * @return 预约人
     */
    @Override
    public List<TourismRecord> selectTourismRecordList(TourismRecord tourismRecord)
    {
        return tourismRecordMapper.selectTourismRecordList(tourismRecord);
    }

    /**
     * 新增预约人
     *
     * @param tourismRecord 预约人
     * @return 结果
     */
    @Override
    public int insertTourismRecord(TourismRecord tourismRecord)
    {
        tourismRecord.setCreateTime(DateUtils.getNowDate());
        return tourismRecordMapper.insertTourismRecord(tourismRecord);
    }

    /**
     * 修改预约人
     *
     * @param tourismRecord 预约人
     * @return 结果
     */
    @Override
    public int updateTourismRecord(TourismRecord tourismRecord)
    {
        return tourismRecordMapper.updateTourismRecord(tourismRecord);
    }

    /**
     * 批量删除预约人
     *
     * @param ids 需要删除的预约人ID
     * @return 结果
     */
    @Override
    public int deleteTourismRecordByIds(Long[] ids)
    {
        return tourismRecordMapper.deleteTourismRecordByIds(ids);
    }

    /**
     * 删除预约人信息
     *
     * @param id 预约人ID
     * @return 结果
     */
    @Override
    public int deleteTourismRecordById(Long id)
    {
        return tourismRecordMapper.deleteTourismRecordById(id);
    }

   @Override
    public AjaxResult FindAll(Integer userId) {
        List<TourismRecord> recordList = tourismRecordMapper.findAll(userId);
        for(TourismRecord tourismRecord : recordList){
            List<TourismPersonnel> tourismPersonnels = tourismPersonnelMapper.selectList(tourismRecord.getId());
            tourismRecord.setPersonnelList(tourismPersonnels);
        }
        return AjaxResult.success(recordList);
    }
}
